﻿
var tagNo = 1000;
function createErrTag(obj, msg, parent, btn)
{
    var tag = getErrTag(obj, parent);
    var pos = obj;
    parent = parent || 0;
    if (!tag)
    {
        tag = $("<div id=\"tip-x-validate-" + (tagNo++) + "\" class=\"tip-x-validate-error\">" + msg + "</div>");
        for (var i = 0; i < parent; i++)
        {
            pos = pos.parent();
        }
        tag.css({ left: pos.offset().left, top: pos.offset().top });
        pos.after(tag);
        obj.bind("click", function ()
        {
            if (obj[0].type.toLowerCase() === "radio")
            {
                tag.show();
                for (var i = 0; i < obj.length; i++)
                {
                    if (obj[i].checked)
                    {
                        tag.hide();
                    }
                }
            } else
            {
                tag.hide();
                obj.removeClass("input-x-validate-error");
            }
        });
        if (btn)
        {
            btn.bind("click", function ()
            {
                tag.hide();
                obj.removeClass("input-x-validate-error");
            });
        }
    } else
    {
        tag.html(msg);
        tag.show();
    }
    if (obj[0].type.toLowerCase() === "text" || obj[0].type.toLowerCase() === "textarea")
    {
        obj.addClass("input-x-validate-error");
    }
    return tag;
}
function getErrTag(obj, parent)
{
    var pos = obj;
    parent = parent || 0;
    for (var i = 0; i < parent; i++)
    {
        pos = pos.parent();
    }
    pos = pos.next("div");
    if (pos.hasClass("tip-x-validate-error"))
    {
        return pos;
    } else
    {
        return null;
    }
}
//提取错误信息
function GetMsgInfo(html)
{
    var resultMsg = "";
    var errorMsg = "";
    var pattern = "<p><img[\\w\\W]*?>([\\w\\W]{1,100})\\s*?<a[\\w\\W]*?>返回</a></p>";
    errorMsg = html.match(pattern);
    if (errorMsg!=null && errorMsg.length >= 2)
    {
        resultMsg = errorMsg[1];
    }
    return resultMsg;
}
//异常处理
function HandlerException(data)
{
    var errorMsg = GetMsgInfo(data);
    if (errorMsg != "")
    {
        alert(errorMsg);
    }
    else if(data.length<=60)
    {
        alert(data);
    }
}
//获取checkbox选中值
function GetCheckBoxSelectedVal(chkName)
{
    var chkList = document.getElementsByName(chkName);
    var result = [];
    for (var i = 0; i < chkList.length; i++)
    {
        if (chkList[i].checked)
        {
            result.push(chkList[i].value);
        }
    }
    return result.join(",");
}
function checkAll(ifall, checkname)
{
    var form = $(ifall).closest('form');
    var checks = $('input[type=checkbox][name=' + checkname + ']', form);
    if (ifall.checked)
    {
        checks.attr('checked', 'checked');
    } else
    {
        checks.removeAttr("checked");
    }
}
//计算区分中英文字符串长度
function GetStrLenByLanguage(str)
{
    var elLen = str.length;
    var CJK = str.match(/[\u4E00-\u9FA5\uF900-\uFA2D]/g);
    if (CJK != null) elLen += CJK.length;
    elLen = Math.ceil(elLen / 2);
    return elLen;
}
//计算字符串长度不区分中英文
function GetStrLen(str)
{
    var elLen = str.length;
    return elLen;
}
// 智联招聘全站通用方法
if (!window.zlzp)
{
   window.zlzp = {};
}

zlzp.App = {
    loading: function (bShow)
    {
        if (!$("#ajaxLoading").length)
        {
            $("body").append('<div id="ajaxLoading" style="display:none;"></div>');
        }
        if (bShow === false)
        {
            $("#ajaxLoading").hide();
        } else
        {
            $("#ajaxLoading").css({
                "position": "absolute",
                "z-index": "999999",
                "left": $(window).width() / 2 - 16 + "px",
                "top": $(window).height() / 2 - 16 + "px"
            }).html('<img src="http://myimg.zhaopin.com/images/new_v3/ani_ajaxload.gif" \/>')
			.show();
        }
    }
};
